/*******************************************************************************
 * Copyright (c) 2010, 2010 Xbeam Project and ChenZhiKong.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 *******************************************************************************/
package org.bellusoft.xbeam.framework;

import java.io.File;
import java.io.InputStream;
import java.util.Collection;
import java.util.Dictionary;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.BundleListener;
import org.osgi.framework.Filter;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;

class BundleContextImpl implements BundleContext{
	
	private BundleEventDispatcher eventDispatcher ; 
	
	private Bundle bundle ; 
	
	private Kernel kernel ; 
	
	public BundleContextImpl() {
		// TODO Auto-generated constructor stub
	}

	public String getProperty(String key) {
		return kernel.getProperty(key);
	}

	public Bundle getBundle() {
		return bundle;
	}

	public Bundle installBundle(String location, InputStream input)
			throws BundleException {
		return kernel.installBundle(location,input);
	}

	public Bundle installBundle(String location) throws BundleException {
		return installBundle(location, null);
	}

	public Bundle getBundle(long id) {
		return kernel.getBundle(id);
	}

	public Bundle[] getBundles() {
		return kernel.getBundles();
	}

	public void addServiceListener(ServiceListener listener, String filter)
			throws InvalidSyntaxException {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public void addServiceListener(ServiceListener listener) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public void removeServiceListener(ServiceListener listener) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public void addBundleListener(BundleListener listener) {
		eventDispatcher.addBundleListener(listener);
	}

	public void removeBundleListener(BundleListener listener) {
		eventDispatcher.removeBundleListener(listener);
	}

	public void addFrameworkListener(FrameworkListener listener) {
		eventDispatcher.addFrameworkListener(listener);
	}

	public void removeFrameworkListener(FrameworkListener listener) {
		eventDispatcher.removeFrameworkListener(listener);
	}

	public ServiceRegistration<?> registerService(String[] clazzes,
			Object service, Dictionary<String, ?> properties) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public ServiceRegistration<?> registerService(String clazz, Object service,
			Dictionary<String, ?> properties) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public <S> ServiceRegistration<S> registerService(Class<S> clazz,
			S service, Dictionary<String, ?> properties) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public ServiceReference<?>[] getServiceReferences(String clazz,
			String filter) throws InvalidSyntaxException {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public ServiceReference<?>[] getAllServiceReferences(String clazz,
			String filter) throws InvalidSyntaxException {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public ServiceReference<?> getServiceReference(String clazz) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public <S> ServiceReference<S> getServiceReference(Class<S> clazz) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public <S> Collection<ServiceReference<S>> getServiceReferences(
			Class<S> clazz, String filter) throws InvalidSyntaxException {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public <S> S getService(ServiceReference<S> reference) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public boolean ungetService(ServiceReference<?> reference) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("TODO");
	}

	public File getDataFile(String filename) {
		return bundle.getDataFile(filename);
	}

	public Filter createFilter(String filter) throws InvalidSyntaxException {
		return FrameworkUtil.createFilter(filter);
	}

	/**
	 * @param kernel2
	 */
	public void setKernel(Kernel kernel) {
		this.kernel = kernel ; 
	}

}
